<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{{ url_for('static',filename='layuiadmin/layui/css/layui.css') }}" media="all">
    <link rel="stylesheet" href="{{ url_for('static',filename='layuiadmin/style/admin.css') }}" media="all">

</head>

<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-btn-group test-table-btn" style="margin-bottom: 10px;" id="data_bar"
                         lay-filter="data_bar">
                    </div>
                    <form class="layui-form" style="padding-bottom: 10px">
                        <div class="layui-input-inline">
                            <input type="text" name="user_id" autocomplete="off"
                                   placeholder="用户手机号或用户名" class="layui-input">
                        </div>

                        <div class="layui-input-inline " style="width: 90px">
                            <button class="layui-btn" id="searchEmailCompany" data-type="reload">
                                <i class="layui-icon" style="font-size: 20px; "></i> 搜索
                            </button>
                        </div>
                    </form>

                    <table class="layui-hide" id="test-table" lay-filter="test-table"></table>


                    <script type="text/html" id="test-table-barDemo">

                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="account">钱包</a>
{#                        <a class="layui-btn layui-btn-warm layui-btn-xs"#}
{#                           lay-href="/cms/user_freed/?user_id={{ '{{ d.id }}' | safe }}">解锁</a>#}
                         <a class="layui-btn layui-btn-warm layui-btn-xs"
                           lay-href="/cms/user_extend_manage/?user_id={{ '{{ d.id }}' | safe }}">身份</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="reset_user">重置</a>
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="user_info">信息</a>
                        <a class="layui-btn layui-btn-xs" lay-event="edit">封号</a>

                        <a class="layui-btn layui-btn-xs" lay-event="unblock">解封</a>

                        <a class="layui-btn layui-btn-xs"
                           lay-href="/cms/user_manage/?parent_id={{ '{{ d.user_id }}' | safe }}">直推</a>
                        <a class="layui-btn layui-btn-xs"
                           lay-href="/cms/user_manage/?submenus_id={{ '{{ d.user_id }}' | safe }}">上级</a>
                        {#                        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>#}
                    </script>
                </div>
            </div>
        </div>
    </div>

</div>

<!-- 展示图片大小 -->
<style type="text/css">
    .layui-table-cell {
        text-align: center;
        height: auto;
        white-space: normal;
    }

    .layui-table img {
        max-width: 100px
    }
</style>


<!-- 添加和修改的弹出层开始 -->
<div style="display: none;padding: 20px" id="saveOrUpdateDiv">
    <form class="layui-form " action="" lay-filter="dataFrm" id="dataFrm">

        <div class="layui-form-item">
            <div class="layui-col-md10">
                <label class="layui-form-label">封号原因：</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" name="token" lay-verify="required" placeholder="请输入名称" autocomplete="off"
                               class="layui-input">
                    </label>
                </div>
            </div>
        </div>


        <input type="hidden" name="user_id_" value="{{ user_id or '' }}">
        <input type="hidden" name="submenus_id" value="{{ submenus_id or '' }}">
        <input type="hidden" name="parent_id" value="{{ parent_id or '' }}">
        <input type="hidden" name="status" value="{{ status }}">
        <input type="hidden" name="id" id="id">

        <div class="layui-form-item" style="margin-top:40px; ">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="doSubmit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>


    </form>
</div>
<!-- 添加和修改的弹出层结束 -->


<!-- 添加和修改的弹出层开始 -->
<div style="display: none;padding: 20px" id="saveOrUpdateDiv3">
    <form class="layui-form " action="" lay-filter="dataFrm3" id="dataFrm3">

        <div class="layui-form-item">
            <div class="layui-col-md10">
                <label class="layui-form-label">手机号：</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" name="phone" lay-verify="required" placeholder="请输入手机号" autocomplete="off"
                               class="layui-input">
                    </label>
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-col-md10">
                <label class="layui-form-label">登录密码：</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" name="pwd" placeholder="请输入要修改的登录密码" autocomplete="off"
                               class="layui-input">
                    </label>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-col-md10">
                <label class="layui-form-label">支付密码：</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" name="pay_pwd" placeholder="请输入要修改的支付密码" autocomplete="off"
                               class="layui-input">
                    </label>
                </div>
            </div>
        </div>

        <input type="hidden" name="user_id_" value="{{ user_id or '' }}">
        <input type="hidden" name="submenus_id" value="{{ submenus_id or '' }}">
        <input type="hidden" name="parent_id" value="{{ parent_id or '' }}">
        <input type="hidden" name="status" value="{{ status }}">
        <input type="hidden" name="id" id="id">

        <div class="layui-form-item" style="margin-top:40px; ">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="doSubmit3">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>


    </form>
</div>
<!-- 添加和修改的弹出层结束 -->

<!-- 添加和修改的弹出层开始 -->
<div style="display: none;padding: 20px" id="saveOrUpdateDiv2">
    <form class="layui-form " action="" lay-filter="dataFrm2" id="dataFrm2">

        <div class="layui-form-item">
            <div class="layui-col-md10">
                <label class="layui-form-label">余额：</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" name="income" lay-verify="required" placeholder="请输入余额(正数加负数减)" autocomplete="off"
                               class="layui-input">
                    </label>
                </div>
            </div>
        </div>

{#         <div class="layui-form-item">#}
{#            <div class="layui-col-md10">#}
{#                <label class="layui-form-label">积分：</label>#}
{#                <div class="layui-input-block">#}
{#                    <label>#}
{#                        <input type="text" name="integral" lay-verify="required" placeholder="请输入积分" autocomplete="off"#}
{#                               class="layui-input">#}
{#                    </label>#}
{#                </div>#}
{#            </div>#}
{#        </div>#}


        <input type="hidden" name="user_id_" value="{{ user_id or '' }}">
        <input type="hidden" name="submenus_id" value="{{ submenus_id or '' }}">
        <input type="hidden" name="parent_id" value="{{ parent_id or '' }}">
        <input type="hidden" name="status" value="{{ status }}">
        <input type="hidden" name="id" id="id">

        <div class="layui-form-item" style="margin-top:40px; ">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="doSubmit2">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>


    </form>
</div>
<!-- 添加和修改的弹出层结束 -->


<script src="{{ url_for('static',filename='layuiadmin/layui/layui.js') }}"></script>
<script>
    layui.config({
        base: '../../../static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'jquery', 'layer', 'form', 'upload'], function () {
        var admin = layui.admin;
        var table = layui.table;
        var upload = layui.upload;
        var $ = layui.jquery;
        var data_user_id = $("input[name='user_id_']").val();
        var data_parent_id = $("input[name='parent_id']").val();
        var data_submenus_id = $("input[name='submenus_id']").val();

        // 参数d是当前行数据
        var statusTpl = function (d) {
            // if else判断
            if (d.open_status == 1) {
                return '<input type="checkbox" lay-filter="switchGoodsID"  value="' + d.user_id + '" lay-skin="switch" switch_goods_id="' + d.user_id + '" lay-text="开启|关闭" checked> ';
            } else {
                return '<input type="checkbox" value="' + d.user_id + '" lay-filter="switchGoodsID" switch_goods_id=""  lay-skin="switch" lay-text="开启|关闭">';
            }
        };

        var tableIns = table.render({
            elem: '#test-table',
            title: '用户信息',
            toolbar: true,
            {#toolbar: "#data_bar",#}
            url: '/cms/user_manage_info/?user_id=' + data_user_id + '&submenus_id=' + data_submenus_id + '&parent_id=' + data_parent_id,
            cols: [[
                {field: 'id', title: 'ID', sort: true, align: 'center', hide: true,},
                {field: 'pay_pwd', title: 'pay_pwd', align: 'center', hide: true,},
                {field: 'blockade', title: 'blockade', sort: true, align: 'center', hide: true,},
                {field: 'user_id', title: 'ID', sort: true, align: 'center', hide: true,},
                {field: 'username', title: '用户名', align: 'center'},
                {field: 'real_name', title: '真实姓名', align: 'center'},
                {field: 'real_status', title: '实名', align: 'center'},
                {field: 'phone', title: '手机号', align: 'center'},
                {field: 'income', title: '余额', sort: true, align: 'center'},
                {field: 'direct_num', title: '直推人数', sort: true, align: 'center'},
                {field: 'team_num', title: '团队人数', sort: true, align: 'center'},
               /* {
                    field: 'open_status', title: '点对点', align: 'center', templet: statusTpl
                },*/

                {field: 'create_time', title: '创建时间', sort: true, align: 'center'},

                {field: 'user_token', title: '封号', align: 'center'},
                {align: 'center', width: 220, fixed: 'right', title: '操作', toolbar: '#test-table-barDemo',}
            ]]
            , page: true
        });


        // 添加数据按钮事件
        $('.test-table-btn .layui-btn').on('click', function () {
            openAdd()
        });


        //监听工具条
        table.on('tool(test-table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'unblock') {
                layer.confirm('您确定要解封么?', function (index) {
                    $.ajax({
                        url: '/cms/user_unblock/',
                        type: "POST",
                        data: data,
                        success: function (data) {
                            if (data['code'] == 200) {
                                //关闭弹框
                                layer.close(mainIndex);
                                //显示提示框
                                layer.msg("成功", {icon: 6});
                                tableIns.reload()
                            } else {
                                layer.msg(data['message'], {icon: 5});
                            }
                        }
                    });
                });
            } else if (obj.event === 'edit') {
                openUpdate(data);
            } else if (obj.event === 'account') {
                openUpdate2(data);
            }
            else if (obj.event === 'user_info') {
                openUpdate3(data);
            }
            else if (obj.event === 'reset_user') {
                layer.confirm('您确定要重置用户实名么?', function (index) {
                    $.ajax({
                        url: '/cms/reset_user_real/',
                        type: "POST",
                        data: data,
                        success: function (data) {
                            if (data['code'] == 200) {
                                //关闭弹框
                                layer.close(mainIndex);
                                //显示提示框
                                layer.msg("成功", {icon: 6});
                                tableIns.reload()
                            } else {
                                layer.msg(data['message'], {icon: 5});
                            }
                        }
                    });
                });
            }
        });


        var url;
        var mainIndex;

        //打开添加页面
        function openAdd() {
            mainIndex = layer.open({
                type: 1,
                title: '添加数据',
                content: $("#saveOrUpdateDiv"),
                {#area: ['800px', '650px'],#}
                area: ['40%', '50%'],
                success: function (index) {
                    //清空表单数据
                    $("#dataFrm")[0].reset();
                    // 清空id数据
                    //document.getElementById("goods_id").value = "";
                    //layui.form.render();
                }
            });
        }


        //打开修改页面
        function openUpdate(data) {
            mainIndex = layer.open({
                type: 1,
                title: '修改数据',
                content: $("#saveOrUpdateDiv"),
                {#area: ['800px', '650px'],#}
                area: ['40%', '50%'],
                success: function (index) {
                    layui.form.val("dataFrm", data);

                    {#// 回显下拉选择框的值#}
                    {#$("#data_id").val(data['data_id']);#}
                    {#layui.form.render('select', 'selFilter');#}

                }
            });
        }

        //保存
        layui.form.on("submit(doSubmit)", function (obj) {
            //序列化表单数据
            var data = obj.field;
            //data['status'] = data_status;
            console.log(data);
            $.ajax({
                url: '/cms/user_blockade/',
                type: "POST",
                data: data,
                success: function (data) {
                    if (data['code'] == 200) {
                        //关闭弹框
                        layer.close(mainIndex);
                        //显示提示框
                        layer.msg("成功", {icon: 6});
                        tableIns.reload();
                        {#window.location.href = "{{ url_for('cms.cms_records') }}"#}
                    } else {
                        layer.msg(data['message'], {icon: 5});
                    }
                }
            });
            return false;

        });


        //打开修改钱包页面
        function openUpdate2(data) {
            mainIndex = layer.open({
                type: 1,
                title: '修改数据',
                content: $("#saveOrUpdateDiv2"),
                {#area: ['800px', '650px'],#}
                area: ['60%', '80%'],
                success: function (index) {
                    data['income'] = '';
                    layui.form.val("dataFrm2", data);

                    {#// 回显下拉选择框的值#}
                    {#$("#data_id").val(data['data_id']);#}
                    {#layui.form.render('select', 'selFilter');#}

                }
            });
        }


        //保存钱包数据
        layui.form.on("submit(doSubmit2)", function (obj) {
            //序列化表单数据
            var data = obj.field;
            //data['status'] = data_status;
            console.log(data);
            $.ajax({
                url: '/cms/update_user_income/',
                type: "POST",
                data: data,
                success: function (data) {
                    if (data['code'] == 200) {
                        //关闭弹框
                        layer.close(mainIndex);
                        //显示提示框
                        layer.msg("成功", {icon: 6});
                        tableIns.reload();
                        {#window.location.href = "{{ url_for('cms.cms_records') }}"#}
                    } else {
                        layer.msg(data['message'], {icon: 5});
                    }
                }
            });
            return false;

        });


        //打开修改用户信息页面
        function openUpdate3(data) {
            mainIndex = layer.open({
                type: 1,
                title: '修改数据',
                content: $("#saveOrUpdateDiv3"),
                {#area: ['800px', '650px'],#}
                area: ['40%', '50%'],
                success: function (index) {
                    layui.form.val("dataFrm3", data);

                    {#// 回显下拉选择框的值#}
                    {#$("#data_id").val(data['data_id']);#}
                    {#layui.form.render('select', 'selFilter');#}

                }
            });
        }


        //保存钱包数据
        layui.form.on("submit(doSubmit3)", function (obj) {
            //序列化表单数据
            var data = obj.field;
            //data['status'] = data_status;
            console.log(data);
            $.ajax({
                url: '/cms/reset_user_pwd/',
                type: "POST",
                data: data,
                success: function (data) {
                    if (data['code'] == 200) {
                        //关闭弹框
                        layer.close(mainIndex);
                        //显示提示框
                        layer.msg("成功", {icon: 6});
                        tableIns.reload();
                        {#window.location.href = "{{ url_for('cms.cms_records') }}"#}
                    } else {
                        layer.msg(data['message'], {icon: 5});
                    }
                }
            });
            return false;

        });



        // 上传图片
        var imgInput = $("input[name='goods_img']");
        upload.render({
            elem: '#upload_btn' //绑定元素
            , url: '/cms/cms_upload/' //上传接口
            , done: function (res) {
                if (res.code == 200) {
                    imgInput.val(res.data.url);
                } else {
                    layer.msg(res.message)
                }
            }
            , error: function () {
                layer.msg('上传失败')
            }
        });

        var linkInput = $("input[name='link_url']");
        upload.render({
            elem: '#upload_btn2' //绑定元素
            , url: '/cms/cms_upload/' //上传接口
            , done: function (res) {
                if (res.code == 200) {
                    linkInput.val(res.data.url);
                } else {
                    layer.msg(res.message)
                }
            }
            , error: function () {
                layer.msg('上传失败')
            }
        });

        // 更改switch开关
        layui.form.on('switch(switchGoodsID)', function (data) {
            //开关是否开启，true或者false
            var checked = data.elem.checked;
            var is_type;
            var contexts;
            if (checked == true) {
                contexts = "开启";
                is_type = 1;
            } else {
                contexts = "关闭";
                is_type = 0;
            }
            //获取所需属性值
            var goods_id = data.value;
            console.log(is_type);
            console.log(goods_id);
            layer.confirm('您确定要' + contexts + '么?', function (index) {
                $.ajax({
                    url: '/cms/user_open_status/',
                    type: "POST",
                    data: {
                        'user_id': goods_id,
                        'status': is_type,
                    },
                    success: function (data) {
                        if (data['code'] == 200) {
                            //关闭弹框
                            layer.close(mainIndex);
                            //显示提示框
                            layer.msg("成功", {icon: 6});
                            tableIns.reload();
                            {#window.location.href = "{{ url_for('cms.cms_records') }}"#}
                        } else {
                            layer.msg(data['message'], {icon: 5});
                        }
                    }
                });
                return false;
            });

        });

    });
</script>
</body>
</html>